const { default: iv } = require('@feidao/service/invoke');
const fs = require('fs');
const path = require('path');
const { default: save } = require('@feidao/service/save');

const spaceid = '@spaceid';
const productid = spaceid;

const params = {
	// put your params here
};

const file_name = '@servicefilename';

const code = fs.readFileSync(path.join(process.cwd(), './service/dist/', file_name) + '.js', {
	encoding: 'utf-8'
});

async function main() {
	try {
		console.log('testing...', file_name);
		const rc = await iv(code, params, 'test', 'test', spaceid);
		console.log(JSON.stringify(rc));
		console.log('update sercie in server...');
		await save(code, spaceid, productid, file_name);
		console.log('saved');
		process.exit();
	} catch (e) {
		console.error(e);
		process.exit(-1);
	}
}

if (require.main === module) {
	main();
}
